var app = getApp();
var util = require("../../utils/util.js");
var siteinfo = require('../../siteinfo.js');
Page({
    data: {
        pdfid: '',
        timedate: '请选择报考时间', //  报考时间
        peType: '', //人员类别
        sbKemu: '',//申报科目
        minDate: new Date(2024, 0, 1).getTime(),
        maxDate: new Date(2024, 2, 31).getTime(),
        fileList: [], //上传毕业证
        zhengshuList: [], // 证书列表
        gongzuoList: [],//工作经历
        occupation: '', // 申报职业
        careerYears: '', // 职业年限
        show: false, // 日历组件显示隐藏
        workUnit: '', //工作单位
        sfznumber: '',// 身份证号
        sfzaddress: '', // 身份证
        radioList: [
            { value: 0, name: '学生' },
            { value: 1, name: '企业员工', },
            { value: 2, name: '社会人员' },
        ], // 单选框选择
        kemuradioList: [
            { value: 0, name: '理论' },
            { value: 1, name: '实操', },
            { value: 2, name: '综合' },
        ], // 申报科目单选框选择
        isSign: false,//是否签名
        loginModal: false,
        isLogin: true, //是否登录
        name: '',
        idCard: '',
        schoolName: '',
        mobile: '',
        state: '', //（0待审核，1待缴费，2未通过，3已分配，4已缴费，9已删除
        OrgName: '',//工作单位
        unitPhone: '',//单位联系电话
        postName: '',//岗位名称
        index: 0,
        orgId: '',
        phoneNum: '',
        // mobile: '',//电话号码
        certificateNo: '',//毕业证书编号
        levelNum: '',//原证书编号
        address: '',//邮寄地址
        declarationPeriod: '',//累计从事申报职业年限
        images: '/image/touxiang.png',
        imagesFront: [],
        imagesReverse: [],
        imagesXueli: [],
        imagesWork: [],
        kemu: [],
        recordCertificate: [], //学历证书 
        workProve: '', //工作证明
        idFront: [], //身份证正面
        idReverse: [], //身份证反面
        typeList: [{
            id: '',
            name: '请选择考生类型'
        }, {
            id: 0,
            name: '在校考生'
        }, {
            id: 1,
            name: '社会考生'
        }],
        genre: [{
            id: null,
            name: '请选择认定类型'
        },
        {
            id: 0,
            name: '正考'
        },
        {
            id: 1,
            name: '补考'
        }],
        index: 0,
        sexList: [{
            id: 0,
            name: '请选择性别'
        }, {
            id: 1,
            name: '男'
        }, {
            id: 2,
            name: '女'
        }],
        indexSex: 0,
        educationList: ["请选择学历", '初中', '高中', '中专', '大专', '大学', '硕士', '博士'], //学历
        indexEducation: 0,
        indexProfile: 0,
        birthTime: '',
        education: '', //学历
        workDate: '',
        //experience:'',
        // dateWork:'',//参加工作时间
        classLevel: '',//原职业等级
        indexKpoints: 0,
        alreadyModal: false,
        gradeList: ["请选择类型", '三级', '四级', '五级'],
        professionList: ["请选择类型", '育婴员', '保育师', '养老护理员'],
        indexNation: 0, //申报职业index
        indexDeclarationLevel: 0,
        indexProfession: 0,
        isProfession: false,
        isNation: false,
        isDeclarationLevel: false,
        isEducation: false,
        declarationLevel: '',//申报认定等级
        profession: '',//申报认定职业
        region: [],
        newsList: [],
        typeIndex: 0,
        type: '',
        inputShowed: false,
        inputVal: "",
        bookList: [], // 证书列表
        workjlList: [], // 工作经历
        a: true,//选中机构后取消下拉框
        list: [{ id: 0, name: '理论' },
        { id: 1, name: '实操' }
        ],
        datalist: {},
    },

    onLoad: function (options) {
        console.log(options);
        this.setData({
            type: options.type,
            datalist: JSON.parse(options.datalist)
        })
    },
    onShow: function () {
        this.handleGetDataList()
    },
    // 参考页面
    handleReference: function () {
        wx.navigateTo({
            url: '/pages/reTemplate/reTemplate'
        })
    },
    // 预览图片
    previewImg: function (e) {
        var index = e.currentTarget.dataset.index;
        var cunzhaoList = e.currentTarget.dataset.dataitem;
        wx.previewImage({
            current: cunzhaoList[index],
            urls: cunzhaoList
        })
    },
    // 寸照预览
    cpreviewImg: function (e) {
        var index = e.currentTarget.dataset.index;
        wx.previewImage({
            current: index,
            urls: [index]
        })
    },
    // 生成pdf
    handleShengcheng() {
        wx.showToast({ title: '加载中', icon: 'loading', duration: 10000 });
        let token = wx.getStorageSync('token');
        wx.request({
            url: siteinfo.siteroot3 + 'jzApi/informationImportUser/savePdf',
            header: {
                'Authorization': token,
                'content-type': 'application/json'
            },
            data: {
                id: this.data.datalist.id,
            },
            method: 'GET',
            success: function (res) {
                // 要插入的字符串
                // const insertStr = 'jinzhiFile/';
                const qieStr = res.data.msg.split('upload/')
                console.log(qieStr);
                // 拼接后的完整URL
                const finalUrl = qieStr[0] + 'jinzhiFile/upload/'  +qieStr[1];
                console.log(finalUrl);
                wx.downloadFile({
                    url: finalUrl,
                    // url: 'https://jinzhiweiye.oss-cn-hangzhou.aliyuncs.com/2022/10/26/6cfa01079b3c4b039dab439be25dbf3b产后恢复职业技能等级标准.pdf',
                    header: {
                        'content-type': 'application/pdf'
                    },
                    success: function (res) {
                        var filePath = res.tempFilePath;
                        // console.log(filePath);
                        wx.openDocument({

                            filePath: filePath,
                            fileType: 'pdf',
                            showMenu: true,
                            success: function (res) {
                                console.log('打开文档成功', res)
                            }
                        })
                    },
                    fail: function (res) {
                        console.log('文件下载失败');
                    },
                    complete: function (res) { },
                })
            },
            complete: () => {
                wx.hideToast()
            }
        });
    },
    /////////////////未审核状态进入///////////////////////////
    handleGetDataList() {
        if (this.data.datalist.name) {
            console.log(this.data.datalist);
            this.setData({
                name: this.data.datalist.name,
                mobile: this.data.datalist.mobile,
                indexSex: this.data.datalist.sex,
                birthTime: this.data.datalist.born,
                indexEducation: this.data.datalist.education,
                major: this.data.datalist.major,
                peType: this.data.datalist.personType,
                certificateType: '0',
                sfzaddress: this.data.datalist.idcardAddress,
                sfznumber: this.data.datalist.idcardNumber,
                workUnit: this.data.datalist.workUnit,
                timedate: this.data.datalist.examTime,
                careerYears: this.data.datalist.workTime,
                indexNation: this.data.datalist.declaredCareers,
                declaredSubject: this.data.datalist.declaredSubject,
                indexDeclarationLevel: this.data.datalist.declaredLevel,
                imagesFront: this.data.datalist.personPhoto,
                idFront: this.data.datalist.personPhoto,
                imagesReverse: JSON.parse(this.data.datalist.idcardPhoto),
                idReverse: JSON.parse(this.data.datalist.idcardPhoto),
                imagesXueli: JSON.parse(this.data.datalist.graducationPhoto),
                recordCertificate: JSON.parse(this.data.datalist.graducationPhoto),
                bookList: this.data.datalist.certificateInfoVos,
                workjlList: this.data.datalist.experinceVos
            })
        }

    },
    ///////////////////////////////////////


    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})